﻿using Framework;
using Protocol.Code;
using UnityEngine;

namespace PokerGame
{
    public class AccountHandler : HandlerBase
    {
        private PromptMsg prompt = new();
        public override void OnReceive(int subCode, object value)
        {
            switch (subCode)
            {
                case AccountCode.LOGIN_S_RES:
                    LoginResponse((int)value);
                    break;
                case AccountCode.REGIST_S_RES:
                    RegistResponse((int)value);
                    break;
                default:
                    break;
            }
        }
        private void LoginResponse(int value)
        {
            switch (value)
            {
                case AccountCode.LOGIN_RET_SUC:
                    //跳转场景
                    LoadSceneMsg msg = new(1, () =>
                    {
                        //TODO:向服务器获取信息
                        Debug.Log("场景加载完成");
                    });
                    Dispatch(AreaCode.SCENE, SceneEvent.LOAD_SCENE, msg);
                    break;
                case AccountCode.LOGIN_RET_ACC_UEXT:
                    prompt.Change("账号不存在", Color.red);
                    Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, prompt);
                    break;
                case AccountCode.LOGIN_RET_ACC_OL:
                    prompt.Change("账号已在线", Color.red);
                    Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, prompt);
                    break;
                case AccountCode.LOGIN_RET_PWD_ERR:
                    prompt.Change("密码错误", Color.red);
                    Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, prompt);
                    break;
                default: break;
            }
        }
        private void RegistResponse(int value)
        {
            switch (value)
            {
                case AccountCode.REGIST_RET_SUC:
                    prompt.Change("注册成功", Color.green);
                    Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, prompt);
                    break;
                case AccountCode.REGIST_RET_ACC_EXT:
                    prompt.Change("账号已存在", Color.red);
                    Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, prompt);
                    break;
                case AccountCode.REGIST_RET_ACC_ERR:
                    prompt.Change("账号不合法", Color.red);
                    Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, prompt);
                    break;
                case AccountCode.LOGIN_RET_PWD_ERR:
                    prompt.Change("密码不合法", Color.red);
                    Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, prompt);
                    break;
                default: break;
            }
        }
    }
}
